myApp.controller('welcome',function($scope,HitService,$timeout){
        $scope.appList={
            data:null,
            totalUsers:0,
            usersPerPage:20,
            pagination:{current:1},
            pageNum:1,
            timeout:{},
            pageChanged:function(newPage){
                this.pageNum=newPage;
                this.getResultsPage(newPage,$scope.keyword);
            },
            getResultsPage:function(pageNumber,keyword){
                HitService.queryLuckList(pageNumber,keyword)
                    .then(function(data){
                        $scope.appList.data=data.result.result;
                        $scope.appList.totalUsers= data.result.count;
                    });
            },
            inputWatch:function(){
                $scope.$watch('keyword',function(newKeyword){
                    if ($scope.appList.timeout[0]) {
                        $timeout.cancel($scope.appList.timeout[0]);
                        delete $scope.appList.timeout[0];
                    }
                    $scope.appList.timeout[0] =$timeout(function() {
                        $scope.appList.getResultsPage(0,newKeyword);
                        delete $scope.appList.timeout[0];
                    }, 500);
                });
            },
            Deleted:function(index){
                var dataID = this.data[index].id;
                HitService.deleteUser(dataID)
                    .then(function(data){
                        if(data.code==200){
                            alert('操作成功');
                            $scope.appList.getResultsPage($scope.appList.pageNum-1,$scope.keyword);
                        }else{
                            alert('操作失败')
                        }
                })
            }
        };
        $scope.appList.inputWatch();
     
}
);